package web.commons;

import application.MySession;
import application.authorization.RolesSession;
import org.apache.wicket.Application;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.spring.injection.annot.SpringBean;

public class LogOffLink extends Link {
    @SpringBean
    private MySession mySession;


    public LogOffLink(String id) {
        super(id);
        if (mySession.getId() == null) {
            this.setVisible(false);
        } else {
            this.setVisible(true);
        }
    }


    public void onClick() {
        RolesSession session = ((RolesSession) getSession());
        session.signOut();
        // homepage is not allowed anymore so we end up at the
        // loginpage
        setResponsePage(Application.get().getHomePage());
        session.invalidate();
//        WaspSession waspSession = ((WaspSession) getSession());
//        if (waspSession.logoff(ctx)) {
//            // homepage is not allowed anymore so we end up at the
//            // loginpage
//            setResponsePage(Application.get().getHomePage());
//            waspSession.invalidate();
//        } else {
//            error(getLocalizer().getString("login.fail.logout", this));
//        }
    }
}

